/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package seGobangClient.Splash;

/**
 *
 * @author micheal
 */
import javax.swing.*;
import java.awt.*;


public class ClientSplash extends JWindow implements Runnable {
	
	private Font myFont = new Font("隶书",3,20);
	
	public static void main(String args[]){
		
		ClientSplash test=new ClientSplash();
		test.run();		
	}
   
    private Thread thread = null;
    private Image logo = null;
    private Color bg_color = new Color(0, 0, 0);
    private Toolkit toolkit =getToolkit();
    private int image_width;
    private int image_height;

    public ClientSplash() {
    	
      logo = Toolkit.getDefaultToolkit().getImage("C://Documents and Settings//Administrator//桌面//VacationTraining//6209affd27e17c4dd7887dd7.jpg");
      loadImage(logo, 0);
      image_width = logo.getWidth(this);
      image_height = logo.getHeight(this);
      setBackground(bg_color);
      setCursor(new Cursor(3));
      setSize(image_width + 10, image_height + 10);      
      int Xpos = (toolkit.getScreenSize().width - getSize().width) / 2;
      int Ypos = (toolkit.getScreenSize().height - getSize().height) / 2;
      setBounds(Xpos, Ypos, getSize().width, getSize().height);
      setVisible(true);
      
    }
    
    private void loadImage(Image image, int ID) {
        if(image != null) {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(image, ID);
            try {
                tracker.waitForID(ID);
            }
            catch(InterruptedException _ex) {}
        }
    }   
    
    public void paint(Graphics g) {
    	
        g.drawImage(logo, 5, 5, image_width, image_height, this);        
       
        g.setColor(new Color(21, 220, 183));
        g.setFont(myFont);
        String direct="正在初始化系统";
        g.drawString(direct, 7, getSize().height - 72);
        
        g.setColor(new Color(255, 255, 255));
        
        
        g.fillRect(5, getSize().height - 70, image_width, 7);
        g.drawRect(5, getSize().height - 70, image_width, 7);        
        
        g.setColor(new Color(140, 207, 244));
        
        int temp=1;
        
        for(int n = 0; n < image_width+5; n += 5)
            try {
             
             Thread.sleep(50);  
             
             if(n>temp*((image_width+5)/6)){           	 
            	 
            	 temp++;
            	 
            	 direct+=".";
            	 
            	 g.drawImage(logo, 5, 5, image_width, image_height, this);        
                 
                 g.setColor(new Color(21, 220, 183));
                 g.setFont(myFont);
                 g.drawString(direct, 7, getSize().height - 72);
                 
                 g.setColor(new Color(255, 255, 255));
                 
                 
                 g.fillRect(5, getSize().height - 70, image_width, 7);
                 g.drawRect(5, getSize().height - 70, image_width, 7);        
                 
                 g.setColor(new Color(140, 207, 244));
            	 
             }
             g.fillRect(5, getSize().height - 70, n, 8);             
            }
            catch(Exception _ex) { }
            
            this.stop();
            setCursor(new Cursor(0));
            System.exit(0);            
        }

    public void run() {
        
        setCursor(new Cursor(3));
        repaint();
        
    }

    public void stop() {
        
        thread = null;
        logo = null;
    }

    public void update(Graphics g) {
        paint(g);
    }
  }
